<?php

Prado::using("System.Web.UI.WebControls.TImage");
 
class TCaptchaImage extends TImage {
	
	/**
	 * OnInit method call service & init image url
	*/	
	public function onInit($param) {
		parent::onInit($param);
		if(!$this->Page->IsPostBack && !$this->Page->IsCallBack) {
			// call captcha service. Has ID of 'captcha'
			$url = $this->getRequest()->constructUrl("captcha", 1);	
			$this->ImageUrl = $url;
		}		
	}
	
	/**
	 * @param code - check if given code is valid
	 * @return boolean if code is valid
	 */
	public function isCodeValid($code) {
		return hash("sha256",$code) == $this->Session['CAPTCHA_SECURITY_CODE'];
	}
 
}
 
?>